﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BankSystem
{
    internal class Bank
    {
        private String _name;
        private List<Account> _accountsList;
        private int GlobalId; // 用于生成全局唯一的六位数账号

        public Bank(String n)
        {
            _name = n;
            _accountsList = new List<Account>();
            GlobalId = 100000;
        }

        public String Name
        {
            get => _name;
        }

        public Boolean CheckAccount(String accountNumber, String password)
        {
            return _accountsList.Exists(
                x => x.AccountNumber == accountNumber && x.Password == password
                );
        }

        public String AddAccount(String password) { 
            string accountNumber = GlobalId.ToString("D6");
            GlobalId++;
            _accountsList.Add(new Account(accountNumber, password));
            return accountNumber;
        }

        public int GetBalance(String accountNumber) {
            return _accountsList.Find(x => x.AccountNumber == accountNumber).Balance;
        }

        public void SetBalance(String accountNumber, int operate,  int amount)
        {
            _accountsList.Find(x => x.AccountNumber == accountNumber).Balance += operate*amount;
        }

        public String AccountInfo(String accountNumber) {
            return _accountsList.Find(x => x.AccountNumber == accountNumber).AccountInfo();
        }
    }
}
